<?php


namespace App\service;


use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class JwtService
{
    private static $key = 'example_key';

    /**
     *生成token
     */
    public static function getToken($data)
    {
        $payload = [
            'iss' => 'http://www.project.com',
            'aud' => 'http://www.project.com',
            'data' => $data
        ];
        return $jwt = JWT::encode($payload, self::$key, 'HS256');
    }

    /**
    *解析token
     */
    public static function decodeToken($token)
    {
        $decoded = JWT::decode($token, new Key(self::$key, 'HS256'));

        return $decoded;
    }
}
